#!/bin/bash

# Raft 入门演示启动脚本

echo "=== Raft 分布式共识算法入门演示 ==="

# 检查Java环境
if ! command -v java &> /dev/null; then
    echo "错误: 未找到Java环境，请先安装Java 8或更高版本"
    exit 1
fi

# 编译代码
echo "1. 编译代码..."
javac -cp src src/main/java/raft/**/*.java src/test/raft/*.java
if [ $? -ne 0 ]; then
    echo "编译失败，请检查代码"
    exit 1
fi
echo "   编译完成"

echo ""
echo "=== 可用的演示程序 ==="
echo ""
echo "1. 基础Raft演示:"
echo "   java -cp src raft.examples.RaftExample"
echo ""
echo "2. 故障转移演示:"  
echo "   java -cp src raft.cmd.RaftFailoverDemo"
echo ""
echo "3. 功能测试:"
echo "   java -cp src raft.test.RaftTest"
echo ""
echo "选择要运行的演示 (1-3, 或按回车退出):"
read choice

case $choice in
    1)
        echo "启动基础Raft演示..."
        java -cp src raft.examples.RaftExample
        ;;
    2)
        echo "启动故障转移演示..."
        java -cp src raft.cmd.RaftFailoverDemo
        ;;
    3)
        echo "启动功能测试..."
        java -cp src raft.test.RaftTest
        ;;
    *)
        echo "退出演示"
        ;;
esac
